load("@bazel_skylib//rules:expand_template.bzl", "expand_template")

expand_template(
    name = "header",
    out = "crypt.h",
    substitutions = {
        "@BEGIN_DECLS@": "__BEGIN_DECLS",
        "@DEFAULT_PREFIX_ENABLED@": "1",
        "@XCRYPT_VERSION_MAJOR@": "4",
        "@XCRYPT_VERSION_MINOR@": "4",
        "@XCRYPT_VERSION_STR@": "4.4",
        "@END_DECLS@": "__END_DECLS",
    },
    template = "//lib:crypt.h.in",
    visibility = ["//lib:__pkg__"],
)

genrule(
    name = "cfg",
    srcs = ["//config"],
    outs = ["config.h"],
    cmd = "$(CP) $< $@",
    cmd_bat = "$(CP) $< $@",
    toolchains = ["@rules_coreutils//coreutils/toolchain/cp:resolved"],
    visibility = ["//lib:__pkg__"],
)

genrule(
    name = "hashes",
    srcs = ["//crypt-hashes"],
    outs = ["crypt-hashes.h"],
    cmd = "$(CP) $< $@",
    cmd_bat = "$(CP) $< $@",
    toolchains = ["@rules_coreutils//coreutils/toolchain/cp:resolved"],
    visibility = ["//lib:__pkg__"],
)

genrule(
    name = "symbol-vers",
    srcs = ["//crypt-symbol-vers"],
    outs = ["crypt-symbol-vers.h"],
    cmd = "$(CP) $< $@",
    cmd_bat = "$(CP) $< $@",
    toolchains = ["@rules_coreutils//coreutils/toolchain/cp:resolved"],
    visibility = ["//lib:__pkg__"],
)

alias(
    name = "libxcrypt",
    actual = "//lib",
    visibility = ["//visibility:public"],
)
